/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import POJO.HocSinhPOJO;
import POJO.QuyDinhPOJO;
import java.sql.ResultSet;
import java.util.ArrayList;

/** @author
 *  ITEC.HCMUS.EDU.VN
 *  Ngô Huy Đạt
 *  0869005
 *  nhdat.itec@gmail.com
 */
public class QuyDinhDAO {

    public static QuyDinhPOJO selectAll() {
        QuyDinhPOJO QD = new QuyDinhPOJO();
        try {
            MySQLDataAccessHelper helper = new MySQLDataAccessHelper();
            helper.open();

            String sql = "SELECT * FROM quydinh";
            ResultSet rs = helper.excecuteQuery(sql);
            rs.next();
            QD.setTuoiMin(rs.getInt("TuoiMin"));
            QD.setTuoiMax(rs.getInt("TuoiMax"));
            QD.setHocSinhMax(rs.getInt("HocSinhMax"));
            QD.setDiemChuan(rs.getFloat("DiemChuan"));

            helper.close();
        } catch (Exception ex) {
            System.out.print(ex.getMessage());
        }
        return QD;
    }
    public static boolean  update(int tuoimin, int tuoimax, int SLHS,float diemchuan) {
        boolean kq = false;
        try {
            MySQLDataAccessHelper helper = new MySQLDataAccessHelper();
            helper.open();

            String sql = String.format("UPDATE quydinh SET TuoiMin=%d,TuoiMax=%d,HocSinhMax=%d,DiemChuan=%f",tuoimin,tuoimax,SLHS,diemchuan);
            int num = helper.excecuteUpdate(sql);
            if(num==1)  kq = true;

            helper.close();
        } catch (Exception ex) {
            System.out.print(ex.getMessage());
        }
        return kq;
    }

}
